/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import controller.CtrCadastroCategoria;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Categoria;
import utils.ExcecaoSCEV;

/**
 *
 * @author lcarlos
 */
@WebServlet(name = "svtLogin", urlPatterns = {"/svtLogin"})
public class svtLogin extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, ExcecaoSCEV {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            
            //Usuário e senha definidos como no arquivo JDialogLogin.java
            String defUsuario = "scev";
            String defSenha = "scev";

            String loginUsuario = request.getParameter("loginUsuario");
            String loginSenha = request.getParameter("loginSenha");
            
            String responseText = "";
            
            if (loginUsuario.equals("")) {
                responseText = "Usuário é de preenchimento obrigatório!";
            } else if (loginSenha.equals("")) {
                responseText = "Senha é de preenchimento obrigatório!";
            } else if (!loginUsuario.equals(defUsuario)) {
                responseText = "Usuário inválido!";
            } else if (!loginSenha.equals(defSenha)) {
                responseText = "Senha inválido!";
            } else {
               //Acesso autorizado.
               response.sendRedirect("menuPrincipal.jsp");
            }

            responseText += "<br/><br/><a href='index.jsp'>Voltar</a>";

            out.println(responseText);

        } finally {
            out.close();
        }
    }
    
    
  // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (ExcecaoSCEV ex) {
            Logger.getLogger(cadCategoriaServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (ExcecaoSCEV ex) {
            Logger.getLogger(cadCategoriaServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
